package com.example.demo.controller;

import com.alibaba.fastjson.JSON;
import com.example.demo.service.ReportDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
@RequestMapping("chaincode/report-detail")
public class ReportDetailController {
    @Autowired
    ReportDetailService reportDetailService;

    @RequestMapping("")
    public String index(){
        return "report-detail controller";
    }

    @RequestMapping("get-all")
    public String getAll() throws Exception {
        return reportDetailService.getAll();
    }

    @RequestMapping("get-one")
    public String getOne(@RequestParam(name = "id") String assetID) throws Exception {
        String s = reportDetailService.getOne(assetID);
        return s;
    }

    @RequestMapping("exists")
    public String exists(@RequestParam(name = "id") String assetID) throws Exception {
        return String.valueOf(reportDetailService.exists(assetID));
    }

    @RequestMapping("create")
    public String create(@RequestBody() String msg) throws Exception {
        return String.valueOf(reportDetailService.create(JSON.parseObject(msg)));
    }

    @RequestMapping("update")
    public String update(@RequestBody() String msg) throws Exception {
        return String.valueOf(reportDetailService.update(JSON.parseObject(msg)));
    }
}
